from string import Template
from config import TEMPLATE_DIR, TEMPLATE_NAME, OUTPUT_DIR


class Generator(object):
    def __init__(self, template_dir=TEMPLATE_DIR, template_name=TEMPLATE_NAME, output_dir=OUTPUT_DIR):
        self.template = template_name
        self.template_dir = template_dir
        self.output_dir = output_dir

    def generate(self) -> None:
        template_content = open(self.template, 'r').read()
        template = Template(template_content)
        target_file_name = self.output_dir + '/' + 'test1.py'
        target_content_lines = [template.substitute(msg='Hello World!')]
        with open(target_file_name, 'w') as f:
            f.writelines(target_content_lines)
        print('Generated file over: {}'.format(target_file_name))
